/**
 * 浏览器cookie
 */
export class CookieUtils {
    static addCookie(objName: string, objValue: any,time=null): void {
        let str = objName + "=" + escape(objValue);
        if(!time){
            str += "; expires=Mon, 22 Mar 3021 15:54:50 GMT";
        }else{
            str += "; expires=" + time;
        }
        document.cookie = str;
    }

    static getCookie(name: string): any {
        let arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
        if(arr=document.cookie.match(reg))
            return unescape(arr[2]);
        else
            return null;
    }

    static delCookie(name: string): void {
        const exp = new Date();
        exp.setTime(exp.getTime() - 1);
        const cval=this.getCookie(name);
        if(cval!=null)
            document.cookie= name + "="+cval+";expires="+exp.toUTCString();
    }
}
